
import java.awt.event.KeyEvent;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.Statement;
import java.text.ParseException;
import java.util.Vector;
import javax.swing.ImageIcon;
import javax.swing.JComboBox;
import javax.swing.JFormattedTextField;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextArea;
import javax.swing.table.DefaultTableModel;
import javax.swing.text.MaskFormatter;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * AddBill.java
 *
 * Created on Aug 12, 2012, 7:10:46 AM
 */
/**
 *
 * @author ADM
 */
public class AddBill extends javax.swing.JPanel {

    float toTal = 0;
    String CusID, cusTypeID, doctorID;
    String emName, emID, orderID, meID, temp = null;
    GetInfo gi = new GetInfo();
    int Discount;

    /** Creates new form AddBill */
    public AddBill(String EmpName) {
        initComponents();
        emName = EmpName;
        gi.GetInfoComboBox("MedicineTypeInfo", cboMetype);
        txtToTal.setEnabled(false);
    }

    public void getAddress(String cusName, JTextArea address) {
        ConnectDB conecttion = new ConnectDB();
        Connection conn = conecttion.Connect();
        ResultSet rs = null;
        try {
            CallableStatement call = conn.prepareCall("{call spCustomerInfoName(?)}");
            call.setString(1, cusName);
            rs = call.executeQuery();
            while (rs.next()) {
                String add = rs.getString("CustomerAddress");
                address.setText(add);
            }
            rs.close();
            call.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void getMedicineName(JComboBox jBoxMe, String NameType) {
        jComboBox3.removeAllItems();
        ConnectDB conecttion = new ConnectDB();
        Connection conn = conecttion.Connect();
        ResultSet rs = null;
        try {
            CallableStatement call = conn.prepareCall("{call spMedicinesInfoNameType(?)}");
            call.setString(1, NameType);
            rs = call.executeQuery();
            while (rs.next()) {
                String add = rs.getString("MedicineName");
                jComboBox3.addItem(add);
            }
            rs.close();
            call.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void getCustomerName(String CustomerNameType) {
        cboCusName.removeAllItems();
        ConnectDB conecttion = new ConnectDB();
        Connection conn = conecttion.Connect();
        ResultSet rs = null;
        try {
            CallableStatement call = conn.prepareCall("{call spCustomersTypeInfo(?)}");
            call.setString(1, CustomerNameType);
            rs = call.executeQuery();
            cboCusName.addItem("Choice");
            cboCusName.addItem("Other");
            while (rs.next()) {
                String add = rs.getString("CustomerName");
                cboCusName.addItem(add);
            }
            rs.close();
            call.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void creatNewPatient() {
        ConnectDB conecttion = new ConnectDB();
        Connection conn = conecttion.Connect();
        CusID = gi.GetInfoString("spLastCustomerID", CusID);
        try {
            CallableStatement call = conn.prepareCall("{call spInsertPatients(?,?,?)}");
            call.setString(1, CusID);
            call.setString(2, txtDoc.getText());
            call.setString(3, null);
            call.execute();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void creatNewDellers() {
        ConnectDB conecttion = new ConnectDB();
        Connection conn = conecttion.Connect();
        CusID = gi.GetInfoString("spLastCustomerID", CusID);
        try {
            CallableStatement call = conn.prepareCall("{call spInsertDellers(?,?,?)}");
            call.setString(1, CusID);
            call.setString(2, null);
            call.setString(3, txtTax.getText());
            call.execute();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void createNewCustormer() {
        if (cboCusName.getSelectedItem().toString().equals("Other")) {
            ConnectDB conecttion = new ConnectDB();
            Connection conn = conecttion.Connect();
            if (cboCusType.getSelectedItem().toString().equals("Seller")) {
                cusTypeID = "2";
            }
            if (cboCusType.getSelectedItem().toString().equals("Patient")) {
                cusTypeID = "1";
            }
            try {
                CallableStatement call = conn.prepareCall("{call spInsertCustomers(?,?,?,?)}");
                call.setString(1, cusTypeID);
                call.setString(2, txtName.getText());
                call.setString(3, jTextArea1.getText());
                call.setString(4, null);
                call.execute();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

    }

    public void createNewOrderLine() {
        orderID = gi.GetInfoString("spInfoLastOrderID", orderID);
        ConnectDB conecttion = new ConnectDB();
        Connection conn = conecttion.Connect();
        for (int i = 0; i < jTable1.getRowCount(); i++) {
            meID = gi.GetInfoStringByName("spMedicinesIDName", jTable1.getValueAt(i, 0).toString(), meID);
            try {
                CallableStatement call = conn.prepareCall("{call spInsertOrderLine(?,?,?,?)}");
                call.setString(1, orderID);
                call.setString(2, meID);
                call.setString(3, jTable1.getValueAt(i, 4).toString());
                call.setString(4, jTable1.getValueAt(i, 5).toString());
                call.execute();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

    }

    public void createNewOrder() {
        if (txtToTal.getText().equals("") || txtDate.getText().equals("    /  /  ") || txtExp.getText().equals("    /  /  ")) {
            JOptionPane.showMessageDialog(this, "invalid input info!!!");
        } else {
            ConnectDB conecttion = new ConnectDB();
            Connection conn = conecttion.Connect();
            String StatusID = null, Paid = null;
            if (!cboCusName.getSelectedItem().toString().equals("Other")) {
                CusID = gi.GetInfoStringByName("spCustomerID", cboCusName.getSelectedItem().toString(), CusID);
            }

            if (txtPaid.getText().equals("")) {
                Paid = "0";
            }
            Paid = txtPaid.getText();
            if (cboStatus.getSelectedItem().toString().equals("Waiting")) {
                StatusID = "1";
            }
            if (cboStatus.getSelectedItem().toString().equals("Complete")) {
                StatusID = "3";
            }
            try {
                CallableStatement call = conn.prepareCall("{call spInsertOrders(?,?,?,?,?,?,?)}");
                call.setString(1, CusID);
                call.setString(2, emName);
                call.setString(3, txtToTal.getText());
                call.setString(4, Paid);
                call.setString(5, StatusID);
                call.setString(6, txtDate.getText());
                call.setString(7, txtExp.getText());
                call.execute();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        cboCusType = new javax.swing.JComboBox();
        jLabel2 = new javax.swing.JLabel();
        txtDate = new javax.swing.JTextField();
        try {
            txtDate = new JFormattedTextField(new MaskFormatter("####/##/##"));
        } catch (ParseException ex) {
            ex.printStackTrace();
        }
        jLabel4 = new javax.swing.JLabel();
        txtExp = new javax.swing.JTextField();
        try {
            txtExp = new JFormattedTextField(new MaskFormatter("####/##/##"));
        } catch (ParseException ex) {
            ex.printStackTrace();
        }
        jLabel5 = new javax.swing.JLabel();
        cboStatus = new javax.swing.JComboBox();
        jLabel6 = new javax.swing.JLabel();
        txtPaid = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        txtName = new javax.swing.JTextField();
        cboCusName = new javax.swing.JComboBox();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();
        jButton4 = new javax.swing.JButton();
        jButCre = new javax.swing.JButton();
        cboMetype = new javax.swing.JComboBox();
        jTextField4 = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        jButAdd = new javax.swing.JButton();
        jButRe = new javax.swing.JButton();
        jComboBox3 = new javax.swing.JComboBox();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jLabel9 = new javax.swing.JLabel();
        txtToTal = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        Doctor = new javax.swing.JLabel();
        txtTax = new javax.swing.JTextField();
        jLabel15 = new javax.swing.JLabel();
        txtDoc = new javax.swing.JTextField();
        txtDisCount = new javax.swing.JTextField();
        jLabel14 = new javax.swing.JLabel();

        jLabel1.setText("Customer Type:");

        jLabel3.setText("Address:");

        cboCusType.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Choice", "Seller", "Patient" }));
        cboCusType.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                cboCusTypeItemStateChanged(evt);
            }
        });

        jLabel2.setText("Date Buy:");

        jLabel4.setText("Expiry Date:");

        jLabel5.setText("Status:");

        cboStatus.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Waiting", "Complete" }));

        jLabel6.setText("Have Paid:");

        txtPaid.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtPaidKeyTyped(evt);
            }
        });

        jLabel12.setText("Customer Name:");

        cboCusName.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                cboCusNameItemStateChanged(evt);
            }
        });

        jTextArea1.setColumns(20);
        jTextArea1.setRows(5);
        jTextArea1.setPreferredSize(new java.awt.Dimension(124, 94));
        jScrollPane1.setViewportView(jTextArea1);

        jButton4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icon/cancel.png"))); // NOI18N
        jButton4.setText("Cancel");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        jButCre.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icon/add.png"))); // NOI18N
        jButCre.setText("Add");
        jButCre.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButCreActionPerformed(evt);
            }
        });

        cboMetype.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Choice" }));
        cboMetype.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                cboMetypeItemStateChanged(evt);
            }
        });

        jTextField4.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jTextField4KeyTyped(evt);
            }
        });

        jLabel7.setText("Medicine Name:");

        jButAdd.setFont(new java.awt.Font("Tahoma", 0, 10));
        jButAdd.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icon/add.png"))); // NOI18N
        jButAdd.setMaximumSize(new java.awt.Dimension(41, 23));
        jButAdd.setMinimumSize(new java.awt.Dimension(41, 23));
        jButAdd.setPreferredSize(new java.awt.Dimension(30, 30));
        jButAdd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButAddActionPerformed(evt);
            }
        });

        jButRe.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icon/delete.png"))); // NOI18N
        jButRe.setPreferredSize(new java.awt.Dimension(30, 30));
        jButRe.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButReActionPerformed(evt);
            }
        });

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Medicine Name", "Medicine Type", "Medicine Unit", "Medicine Price", "Quantity", "Total Price"
            }
        ));
        jScrollPane2.setViewportView(jTable1);

        jLabel9.setText("Total:");

        jLabel10.setText("$");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap(636, Short.MAX_VALUE)
                .addComponent(jLabel9)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(txtToTal, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel10)
                .addContainerGap())
            .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 802, Short.MAX_VALUE)
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 143, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtToTal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel10)
                    .addComponent(jLabel9))
                .addContainerGap(19, Short.MAX_VALUE))
        );

        jLabel11.setText("Medicine Type:");

        jLabel8.setText("Quantity:");

        jLabel13.setText("yyyy/mm/dd");

        Doctor.setText("Doctor:");

        txtTax.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtTaxActionPerformed(evt);
            }
        });

        jLabel15.setText("Code of Tax:");

        jLabel14.setText("Discount(%):");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addGap(46, 46, 46)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel1)
                    .addComponent(jLabel12)
                    .addComponent(jLabel3)
                    .addComponent(jLabel11)
                    .addComponent(jLabel7))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jComboBox3, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(cboMetype, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jScrollPane1, 0, 0, Short.MAX_VALUE)
                    .addComponent(cboCusName, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(cboCusType, 0, 124, Short.MAX_VALUE)
                    .addComponent(txtName))
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(49, 49, 49)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel2)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jLabel15)
                                    .addComponent(Doctor)
                                    .addComponent(jLabel14))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(txtDisCount)
                                    .addComponent(txtDoc)
                                    .addComponent(txtTax, javax.swing.GroupLayout.DEFAULT_SIZE, 128, Short.MAX_VALUE))
                                .addGap(21, 21, 21)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jLabel6)
                                    .addComponent(jLabel5)
                                    .addComponent(jLabel4)))))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 138, Short.MAX_VALUE)
                        .addComponent(jLabel8)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(60, 60, 60)
                        .addComponent(jButAdd, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButRe, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(37, 37, 37)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(txtExp, javax.swing.GroupLayout.DEFAULT_SIZE, 136, Short.MAX_VALUE)
                    .addComponent(cboStatus, 0, 136, Short.MAX_VALUE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel13, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 47, Short.MAX_VALUE))
                    .addComponent(txtDate, javax.swing.GroupLayout.DEFAULT_SIZE, 136, Short.MAX_VALUE)
                    .addComponent(txtPaid, javax.swing.GroupLayout.DEFAULT_SIZE, 136, Short.MAX_VALUE))
                .addGap(61, 61, 61))
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(614, Short.MAX_VALUE)
                .addComponent(jButCre, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton4)
                .addGap(50, 50, 50))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addGap(25, 25, 25)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(cboCusType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel1))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel12)
                            .addComponent(cboCusName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtExp, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(Doctor)
                            .addComponent(jLabel4)
                            .addComponent(txtDoc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel3))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(cboMetype, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel11))
                        .addGap(11, 11, 11)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jComboBox3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel7)
                            .addComponent(jLabel8)
                            .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jButRe, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jButAdd, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel13, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtDate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel2))
                        .addGap(72, 72, 72)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(cboStatus, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtTax, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel15))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtPaid, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtDisCount, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel14))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButCre)
                    .addComponent(jButton4))
                .addGap(104, 104, 104))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 805, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 520, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jButCreActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButCreActionPerformed
        ImageIcon icon;
        icon = new ImageIcon("icon/question.png");
        int show = JOptionPane.showConfirmDialog(this, "are you sure?", null, 0, 1, icon);
        if (show == JOptionPane.YES_OPTION) {
            if (cboCusType.getSelectedItem().toString().equals("Choice") || cboCusName.getSelectedItem().toString().equals("Choice") || jTable1.getRowCount() < 0) {
                JOptionPane.showMessageDialog(this, "invalid Input info!!!");
            } else {
                createNewCustormer();
                if (cboCusType.getSelectedItem().toString().equals("Seller") && cboCusName.getSelectedItem().toString().equals("Other")) {
                    creatNewDellers();
                    System.out.println(CusID);
                }
                if (cboCusType.getSelectedItem().toString().equals("Patient") && cboCusName.getSelectedItem().toString().equals("Other")) {
                    creatNewPatient();
                    System.out.println(CusID);
                }
                createNewOrder();
                createNewOrderLine();
                StatisticalBills stabill = new StatisticalBills(emName);
                MedicalStore.setDefaultLookAndFeelDecorated(true);
                MedicalStore.mains.removeAll();
                MedicalStore.mains.add("", stabill);
            }

        }


    }//GEN-LAST:event_jButCreActionPerformed

    private void cboCusTypeItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cboCusTypeItemStateChanged

        txtTax.setEnabled(false);
        if (evt.getStateChange() == java.awt.event.ItemEvent.SELECTED) {
            getCustomerName(cboCusType.getSelectedItem().toString());
        }
        if (cboCusType.getSelectedItem().toString().equals("Patient")) {
            txtDoc.setEnabled(true);
            txtTax.setEnabled(false);
        }
        if (!cboCusType.getSelectedItem().toString().equals("Patient")) {
            txtDoc.setEnabled(false);
            txtTax.setEnabled(true);
        }
    }//GEN-LAST:event_cboCusTypeItemStateChanged

    private void jButAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButAddActionPerformed
        temp = txtDisCount.getText();
        try {
            Discount = Integer.parseInt(temp);
            if (Discount > 100) {
                JOptionPane.showMessageDialog(this, "Discount<=100!!!");
            } else {

                ConnectDB conecttion = new ConnectDB();
                Connection conn = conecttion.Connect();
                DefaultTableModel model;
                int j = 0;
                String mang[];
                if (jTextField4.getText().equals("")) {
                    JOptionPane.showMessageDialog(this, "Please Input Quantity");
                } else {
                    try {
                        model = (DefaultTableModel) jTable1.getModel();
                        CallableStatement call = conn.prepareCall("{call spMedicinesInfoName(?)}");
                        call.setString(1, jComboBox3.getSelectedItem().toString());
                        ResultSet rs = call.executeQuery();
                        ResultSetMetaData rsmd = rs.getMetaData();
                        int NumOfCol = rsmd.getColumnCount();
                        mang = new String[NumOfCol];
                        for (int i = 1; i <= NumOfCol; i++) {
                            mang[j] = rsmd.getColumnName(i);
                            j++;
                        }
                        while (rs.next()) {
                            Vector v = new Vector();
                            v.addElement(rs.getString("MedicineName"));
                            v.addElement(rs.getString("MedicineTypeName"));
                            v.addElement(rs.getString("MedicineUnit"));
                            v.addElement(rs.getString("MedicinePrice"));
                            String quantity = jTextField4.getText();
                            v.addElement(quantity);
                            String Price = (String) v.get(3);
                            float temp = Float.parseFloat(Price);
                            float temp1 = Float.parseFloat(quantity);
                            float toTalPrice = temp * temp1;
                            toTalPrice = toTalPrice * Discount / 100;
                            v.addElement(toTalPrice);
                            toTal = toTal + toTalPrice;
                            model.addRow(v);
                            txtToTal.setText(String.valueOf(toTal));
                            jTextField4.setText("");

                        }
                        rs.close();
                        call.close();

                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
        } catch (Exception e) {
            JOptionPane.showMessageDialog(this, "Discount not is number!!!");
        }
    }//GEN-LAST:event_jButAddActionPerformed

    private void jButReActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButReActionPerformed
        DefaultTableModel model = (DefaultTableModel) jTable1.getModel();
        int nRow = jTable1.getSelectedRow();
        String TotalPrice = jTable1.getValueAt(nRow, 5).toString();
        float temp = Float.parseFloat(TotalPrice);
        toTal -= temp;
        txtToTal.setText(String.valueOf(toTal));
        jTextField4.setText("");
        model.removeRow(nRow);


    }//GEN-LAST:event_jButReActionPerformed

    private void cboMetypeItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cboMetypeItemStateChanged
        getMedicineName(jComboBox3, cboMetype.getSelectedItem().toString());
    }//GEN-LAST:event_cboMetypeItemStateChanged

    private void cboCusNameItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cboCusNameItemStateChanged
        if (evt.getStateChange() == java.awt.event.ItemEvent.SELECTED) {
            jTextArea1.setText("");
            txtName.setText("");
            txtTax.setText("");



            if (cboCusName.getSelectedItem().toString().equals("Other")) {
                txtName.setEnabled(true);
            } else {
                if (!cboCusName.getSelectedItem().toString().equals("Choice")) {
                    txtDisCount.setEditable(false);
                    txtName.setEnabled(false);
                    getAddress(cboCusName.getSelectedItem().toString(), jTextArea1);
                    txtName.setText(cboCusName.getSelectedItem().toString());
                    CusID = gi.GetInfoStringByName("spCustomerID", cboCusName.getSelectedItem().toString(), CusID);
                    String discount = null;
                    discount = gi.GetInfoStringByName("spCustomerDiscount", CusID, discount);
                    txtDisCount.setText(discount);
                } else {
                    txtDisCount.setText("");
                    txtDisCount.setEditable(true);

                }
            }

        }





    }//GEN-LAST:event_cboCusNameItemStateChanged

    private void jTextField4KeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField4KeyTyped
        int key = evt.getKeyChar();
        String stTest = "0123456789";
        if (key != KeyEvent.VK_BACK_SPACE
                && key != KeyEvent.VK_DELETE
                && key != KeyEvent.VK_ENTER) {
            int flag = 0;
            if (stTest.indexOf(evt.getKeyChar()) == -1) {
                flag++;
                JOptionPane.showMessageDialog(this, "Must enter number only");
            }
            if (cboMetype.getSelectedItem().toString().equals("Choice")) {
                flag++;
                JOptionPane.showMessageDialog(this, "Please Choice Medician fist!!!");
            }
            if (flag > 0) {
                evt.consume();
            }
        }
    }//GEN-LAST:event_jTextField4KeyTyped

    private void txtPaidKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtPaidKeyTyped
        int key = evt.getKeyChar();
        String st = txtPaid.getText();
        String stTest = "0123456789";
        if (key != KeyEvent.VK_BACK_SPACE
                && key != KeyEvent.VK_DELETE
                && key != KeyEvent.VK_ENTER) {
            int flag = 0;
            if (stTest.indexOf(evt.getKeyChar()) == -1) {
                flag++;
                JOptionPane.showMessageDialog(this, "Must enter number only");
            }

            if (flag > 0) {
                evt.consume();
            }
        }
    }//GEN-LAST:event_txtPaidKeyTyped

    private void txtTaxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtTaxActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtTaxActionPerformed

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        StatisticalBills stabill = new StatisticalBills(emName);
        MedicalStore.setDefaultLookAndFeelDecorated(true);
        MedicalStore.mains.removeAll();
        MedicalStore.mains.add("", stabill);

    }//GEN-LAST:event_jButton4ActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel Doctor;
    private javax.swing.JComboBox cboCusName;
    private javax.swing.JComboBox cboCusType;
    private javax.swing.JComboBox cboMetype;
    private javax.swing.JComboBox cboStatus;
    private javax.swing.JButton jButAdd;
    private javax.swing.JButton jButCre;
    private javax.swing.JButton jButRe;
    private javax.swing.JButton jButton4;
    private javax.swing.JComboBox jComboBox3;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTable jTable1;
    private javax.swing.JTextArea jTextArea1;
    private javax.swing.JTextField jTextField4;
    private javax.swing.JTextField txtDate;
    private javax.swing.JTextField txtDisCount;
    private javax.swing.JTextField txtDoc;
    private javax.swing.JTextField txtExp;
    private javax.swing.JTextField txtName;
    private javax.swing.JTextField txtPaid;
    private javax.swing.JTextField txtTax;
    private javax.swing.JTextField txtToTal;
    // End of variables declaration//GEN-END:variables
}
